import * as types from './types'

const mutations = {
    [types.LOGIN]: (state, data) => {
        localStorage.setItem('token', data.id)
        // localStorage.token = data
        localStorage.setItem('userInfo', JSON.stringify(data))
        localStorage.setItem('username', data.username);
        state.token = data.id
    },
    [types.LOGOUT]: (state) => {
        localStorage.removeItem('token');
        localStorage.removeItem('userInfo');
        localStorage.removeItem('username');
        state.token = null
    },
    [types.USERNAME]: (state, data) => {
        //localStorage.setItem('username', data)
        state.username = localStorage.getItem('username')
    },
    [types.USERINFO]: (state, data) => {
        // localStorage.setItem('userinfo', data)
        data = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : {}
        state.username = data
    }
}
export default mutations
